package com.ziyun.erp.web.api.purchase;

import com.ziyun.erp.common.e.purchase.MaterialSupplierStatusEnum;
import com.ziyun.erp.common.utils.JsonUtils;
import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.purchase.entity.StoreMaterialSupplierEntity;
import com.ziyun.erp.modules.purchase.service.StoreMaterialSupplierService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.utils.StringUtil;
import io.renren.common.utils.UserUtil;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 采购供应商表
 *
 * @author guizhao
 * @date 2018-09-25 16:27:18
 */
@RestController
@RequestMapping("port/purchase/storematerialsupplier")
public class StoreMaterialSupplierControllerApi {
    @Autowired
    private StoreMaterialSupplierService storeMaterialSupplierService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = storeMaterialSupplierService.queryPage(params);

        //存放枚举类到userdata
        Map<String, List> mapEnum = new HashMap<>();
        List<Map<String, Object>> materialSupplierStatusEnum = JsonUtils.enumToList(MaterialSupplierStatusEnum.class);
        mapEnum.put("materialSupplierStatusEnum",materialSupplierStatusEnum);

        return R.ok().put("page", page).put("userData", mapEnum);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Map<String,Object> paramBodyMap){
        String storeMaterialSupplierStr = com.utility.JsonUtils.object2String(paramBodyMap.get("storeMaterialSupplier"));
        StoreMaterialSupplierEntity storeMaterialSupplier = com.utility.JsonUtils.string2Object(storeMaterialSupplierStr,StoreMaterialSupplierEntity.class);

        storeMaterialSupplierService.insert(storeMaterialSupplier);
        return R.ok();
    }

}
